$(function () {
    let id = localStorage.getItem("productId");
    // let title = localStorage.getItem("productTitle");
    if (id != null) {
        // getCuisineFindAll();
        findById(id);
    }
    localStorage.setItem("productId", null);
})

function findById(id) {
    let data=myAjax("/back/product/findById",{id: id},"get");
    setCuisine(data.productModel);
}

function setCuisine(data) {
    let html = '';
    let productModel = data;
    let list = data.list;
    for (let i = 0; i < list.length; i++) {
        html += ' <option value="' + list[i].id + '">' + list[i].name + '</option>';
    }
    $("#cuisine").html(html);
    setData(productModel);
}

function setData(data) {
    // $('#cuisine option[text=' + data.cuisineName + ']').attr('selected', true);
    $("#id").val(data.id);
    $("#title").val(data.title);
    $("#content").val(data.content);
    $('#cuisine option[value=' + data.cuisineId + ']').attr('selected', true);

}
function productUpdate() {
    //    取得页面的值
    let data = new FormData();
    data.append("cuisine", $("#cuisine").val());
    data.append("title", $("#title").val());
    data.append("imgHref", $("#imgHref")[0].files[0]);
    data.append("content", $("#content").val());
//    调用后台
    let da = myImgAjax('/back/product/update', data, "post");
    if (da.count == 1) {
        $('#right').load('/back/product/productManange.html');
    } else {
        alert("编辑产品失败");
    }
}